home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / Extension Shell 1.5 / Sample Extensions (1.5) / Bell Test ƒ / PlaySound.c < prev   
C/C++ Source or Header  |  1995-11-01  |  2KB  |  119 lines

  1. /*    NAME:
  2.         PlaySound.c
  3.  
  4.     WRITTEN BY:
  5.         Dair Grant
  6.                 
  7.     DESCRIPTION:
  8.         This file contains a Code resource to be installed as a code block in
  9.         the System Heap.
  10.  
  11.     NOTES:
  12.         When we are called, we play the sound handle contained in the address
  13.         table.
  14.  
  15.     ___________________________________________________________________________
  16. */
  17. #include <Gestalt.h>
  18. #include <Sound.h>
  19. #include "A4Stuff.h"
  20. #include "SetupA4.h"
  21. #include "BT Constants.h"
  22. #include "BT AddrsTable.h"
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. //=============================================================================
  39. //        Global Variables                                                                 
  40. //-----------------------------------------------------------------------------
  41. Handle        gTheSoundToPlay;
  42. Boolean        gAlreadyRan = false;
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. //=============================================================================
  59. //        Private function prototypes                             
  60. //-----------------------------------------------------------------------------
  61. pascal    void main(void);
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. //=============================================================================
  78. //        main : Entry point to our code resource.                                                                 
  79. //-----------------------------------------------------------------------------
  80. //        Note :    We get hold of the handle to the sound from our address table,
  81. //                and play it.
  82. //-----------------------------------------------------------------------------
  83. pascal void main(void)
  84. {    long                oldA4;
  85.     OSErr                theErr;
  86.     BTAddressTable        *theAddressTable;
  87.  
  88.  
  89.  
  90.  
  91.     // Set up A4
  92. #ifndef powerc
  93.     oldA4 = SetCurrentA4();
  94. #endif
  95.  
  96.     
  97.     
  98.     // If we've not already been called, do our one time initialisation stuff
  99.     if (!gAlreadyRan)
  100.         {
  101.         Gestalt(kBellTestAddressTable, (long *) &theAddressTable);        
  102.         gTheSoundToPlay    = theAddressTable->theSound;
  103.         gAlreadyRan        = true;
  104.         }
  105.     
  106.  
  107.     
  108.     // Play the sound
  109.     if (gTheSoundToPlay)
  110.         theErr = SndPlay(nil, (SndListHandle) gTheSoundToPlay, true);
  111.  
  112.  
  113.  
  114.     // Restore A4 and return
  115. #ifndef powerc
  116.     SetA4(oldA4);
  117. #endif
  118. }
  119.